﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// 委外扣减
    /// </summary>
    public class OutsourceDeductJob : IJobService
    {
        private readonly IOutsourceDeductRepository outsourceDeduct;

        public OutsourceDeductJob(IOutsourceDeductRepository _outsourceDeduct)
        {
            this.outsourceDeduct = _outsourceDeduct;
        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<WmsSubcontractData> wmsSubcontracts = outsourceDeduct.GetOutsourceDeductInfo();
                if (wmsSubcontracts.Count <= 0)
                {
                    return "没有委外待扣减的数据！";
                }

                bool bl = outsourceDeduct.InsertOutsourceDeductInfo(wmsSubcontracts);
                if (bl == true)
                {
                    return "委外待扣减数据同步成功！";
                }
                else
                {
                    return "委外待扣减数据同步失败！";
                }

            }
            catch (Exception ex) 
            {
                LogHelper.Error("生成委外扣减错误！" + ex);
                return "生成委外扣减错误！" + ex.Message;
            }
        }
    }
}
